package com.oocl.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.oocl.pojo.User;
import com.oocl.util.Md5Digect;

@Component
@Aspect
public class PwdAspect {
	private final static String p1="execution(* com.oocl.service.UserService.addUser(..))";
	private final static String p2="execution(* com.oocl.service.UserService.checkUser(..))";
	
	@Around(p1)
	public Object AroundAddUser(ProceedingJoinPoint joinPoint){
		Object object = null;
		User user = (User) joinPoint.getArgs()[0];
		user.setPassword(Md5Digect.GetMD5Code(user.getPassword()));
		try {
			object = joinPoint.proceed(new Object[]{user});
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return object;
	}
	
	@Around(p2)
	public Object aroundCheckUser(ProceedingJoinPoint joinPoint){
		Object object = null;
		User user = (User) joinPoint.getArgs()[0];
		user.setPassword(Md5Digect.GetMD5Code(user.getPassword()));
		try {
			object = joinPoint.proceed(new Object[]{user});
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return object;
	}
}
